<%@page import="tools.EmailValidator"%>
<%@page import="accessor.CustomerAccessor"%>
<%@page import="tools.MyTool"%>
<%@page import="java.util.Iterator"%>
<%@page import="accessor.HomeProductAccessor"%>
<%@page import="accessor.Products"%>
<%@include file="no_banner_header.jsp" %>

<%
    if(customer!=null){
        response.sendRedirect("address_order.jsp");
    }
    String loginError = "";
    if (request.getParameter("btnLogin") != null) {
        String loginEmail = request.getParameter("login_email");
        String loginPassword = request.getParameter("login_password");
        if (loginEmail != "" && loginPassword != "" && new EmailValidator().validate(loginEmail)) {
            customer = new CustomerAccessor().getLoginCustomer(loginEmail, loginPassword);
            if (customer != null) {
                request.getSession().setAttribute("customer", customer);
                response.sendRedirect("address_order.jsp");
            } else {
                loginError = "Incorrect user name or password!";
            }
        } else {
            if (loginEmail == "") {
                loginError = "Please enter email!<br/>";
            }
            if(!new EmailValidator().validate(loginEmail)){
                loginError = "Please enter valid email!<br/>";
            }   
            if (loginPassword == "") {
                loginError += "Please enter password!";
            }
        }
    }
%>
<link href="../assets/css/frontend/order.css" rel="stylesheet" type="text/css" media="screen" />
<div>
    <script>
        $(document).ready(function() {
            $('#step2').addClass('current');
        });
    </script>
    <div id="order_step">
        <h4>Steps of Order</h4>
        <p>
            <a id="step1" href="home_order.jsp">Products</a>
            <a id="step2" href="login_order.jsp">Login</a>
            <a id="step3" href="address_order.jsp">Address</a>
            <a id="step4" href="summary_order.jsp">Order</a>
        </p>
    </div>

    <div class="break_line"></div>   
    <div class="user_infor" style="margin-top: 10px;">
        <div class="order_box_2">
            <form action="register.jsp" method="post">
                <h4>CREATE YOU ACCOUNT</h4>
                <div id="order_box_2_content">
                    <p>ENTER YOUR EMAIL ADDRESS</p>
                    <p style="margin-top: 8px;text-transform: uppercase;">EMAIL:</p>
                    <p><input type="text" class="textboxEffect" id="reg_email" name="reg_email"/></p>
                    <p><input type="submit"  class="submit" name="btnRegister" value="REGISTER" /></p>
                    <p  style="margin-top: 8px;text-transform: uppercase;"></p>
                    <p></p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                </div>            
            </form>
        </div>
        <div class="order_box_2 last" style="float: right;">
            <form action="" method="post">
                <h4>ALREADY REGISTERED! LOGIN HERE</h4>
                <div id="order_box_2_content">
                    <p>ENTER YOUR EMAIL AND PASSWORD TO LOGIN:</p>
                    <p style="margin-top: 8px;text-transform: uppercase;">EMAIL:</p>
                    <p><input type="text" class="textboxEffect" name="login_email" value="<%=request.getParameter("login_email")!=null?request.getParameter("login_email"):""%>"/></p>
                    <p style="margin-top: 8px;text-transform: uppercase;">PASSWORD:</p>
                    <p><input type="password" class="textboxEffect" name="login_password"/></p>
                    <p><input type="submit" name="btnLogin" value="LOGIN" class="submit" /></p>
                    <p style="color: red"><%=loginError%></p>
                </div>
            </form>
        </div>
    </div>
</div>                              

<div style="clear: both;">&nbsp;</div>
<%@include file="footer.jsp" %>